﻿//this is a debug tool used in calendar
function profile(func, name) {
    if (!profile[name]) {
        profile[name] = { total: 0, count: 0, max: 0 };
    }
    var start = new Date();
    func();
    var end = new Date();
    var time = end - start;
    profile[name].total += time;
    profile[name].count += 1;
    if (time > profile[name].max) {
        profile[name].max = time;
    }
}
function showProfileResult() {
    var result = [];

    for (var name in profile) {
        if (name != 'prototype') {
            result.push({ total: profile[name].total, text: ("total:" + profile[name].total + ":" + name + " avg:" + profile[name].total / profile[name].count + " max:" + profile[name].max + " count:" + profile[name].count) });
            profile[name] = { total: 0, count: 0, max: 0 };
        }
    }

    result = $(result).sort(function(a, b) {
        if (a.total > b.total) return -1;
        else return 1;
    });

    var str = "";
    $.each(result, function() {
        str += this.text + "\n";
    });
    alert(str);
}
